<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Cache;

class CheckToken
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        // 1 获取token信息;
        $token = $request->bearerToken();

        // 2 在缓存中匹配你传过来的token;
        $json_str = Cache::get($token);

        // 3 判断是否匹配到;
        if(!$json_str){
            return response()->json(["msg"=>"您还没有登录!"],401);
        }

        return $next($request);


    }



}
